#ifndef REGISTERDIALOG_H
#define REGISTERDIALOG_H
#include <QDialog>
#include <QJsonObject>
#include <QMap>
#include <QTimer>
#include "global.h"
#include <functional>
namespace Ui {
class RegisterDialog;
}
// 注册页面逻辑
class RegisterDialog : public QDialog
{
    Q_OBJECT

public:
    explicit RegisterDialog(QWidget *parent = nullptr, unsigned int countDown = 5);
    ~RegisterDialog();
private slots:
    void on_reg_btn_cancel_clicked();
    void on_reg_btn_req_clicked();
    // 注册请求发送成功解析返回值
    void slot_reg_mod_finish(ReqId id, QString res, ErrorCode ec);
    void on_reg_btn_ok_clicked();

    void on_reg_btn_back_clicked();

private:
    Ui::RegisterDialog *ui;
signals:
    void sigSwitchLogin();

private:
    void showTip(const QString &, bool success = false);
    // 注册
    void initHttpHandlers();
    QMap<ReqId, std::function<void(const QJsonObject &)>> _handlers;
    bool CheckUserValid();
    bool CheckEmailValid();
    bool CheckPassWordValid();
    bool CheckVerifyValid();
    void AddTipErr(TipErr te, QString tips);
    void DelTipErr(TipErr te);
    void ChageTipPage();
    QMap<TipErr, QString> _tip_errs;
    QTimer *_timer;
    int _countDown;
};

#endif // REGISTERDIALOG_H
